﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using WindowsFormsApplication3;

namespace bsy
{
    public partial class sy_selectcustormer_Form : Form
    {
        //连接字符串
        private string connStr = Properties.Settings.Default.bsyConnectionString;
        public sy_selectcustormer_Form()
        {
            InitializeComponent();
        }

        private string cusId;

        public string CusId
        {
            get { return cusId; }
            set { cusId = value; }
        }
        private string cusName;

        public string CusName
        {
            get { return cusName; }
            set { cusName = value; }
        }
        private void sy_selectcustormer_Form_Load(object sender, EventArgs e)
        {
            
            show_sy_selectcustormer_dgv("");
        }

        //显示顾客列表
        private void show_sy_selectcustormer_dgv(string keyword)
        {

            string sql = string.Format("select customer_id ID,number 编号,name 姓名,phone 联系电话 from customer where name like '%{0}%'",keyword);
            DataSet ds = new DataSet();
            ds = CommonDB.Query(sql);
            if (ds.Tables[0].Rows.Count > 0) {
                this.sy_selectcustormer_dgv.DataSource = ds.Tables[0].DefaultView;
                this.sy_selectcustormer_dgv.Columns[0].Visible = false;//第一列不显示
            }
            ds.Dispose();
        }

        private void sy_selectcustormer_dgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
            }
            else
            {
                 cusId = this.sy_selectcustormer_dgv.Rows[e.RowIndex].Cells[0].Value.ToString();//获得本行第一个单元格的数据，以此类推
                 cusName = this.sy_selectcustormer_dgv.Rows[e.RowIndex].Cells[2].Value.ToString();//获得本行第一个单元格的数据，以此类推
                 this.DialogResult = DialogResult.OK;
                 this.Close();
            }
        }

        private void search_Click(object sender, EventArgs e)
        {
           
            if (string.Empty != keyword.Text)
            {
                show_sy_selectcustormer_dgv(keyword.Text.ToString().Trim());
            }
            else {

                show_sy_selectcustormer_dgv("");
            }
        }

    }
}
